//
//  UITableView+HYScroll.m
//  HYSmileiOS
//
//  Created by SMC-MAC on 16/4/28.
//  Copyright © 2016年 heyou. All rights reserved.
//

#import "UITableView+HYScroll.h"

@implementation UITableView (HYScroll)

/**
 *  覆盖系统方法，返回TURE
 *  TableView上添加按钮，点击按钮滚动，需要重写此函数
 *
 *  @param view
 *
 *  @return TRUE
 */
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    return YES;
}

/**
 *  禁止点击延迟效果
 */
- (void)hy_disableTouchDelay {
    self.delaysContentTouches = NO;
    self.canCancelContentTouches = YES;
    NSArray* subview = [self subviews];
    for (id view in subview) {
        if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewWrapperView"]) {
            // this test is necessary for safety and because a "UITableViewWrapperView" is NOT a UIScrollView in iOS7
            if([view isKindOfClass:[UIScrollView class]]) {
                // turn OFF delaysContentTouches in the hidden subview
                UIScrollView *scroll = (UIScrollView *)view;
                scroll.delaysContentTouches = NO;
            }
            break;
        }
    }
}

/**
 *  想tableview注册自定义XIB，重用标识为Class的名字
 *
 *  @param cls 需要注册的类名
 */
- (void)registerXibWithClass:(Class)cls {
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *identifier = NSStringFromClass(cls);
    [self registerNib:[UINib nibWithNibName:identifier bundle:mainBundle] forCellReuseIdentifier:identifier];
}

@end
